package unittest;

import static org.junit.Assert.assertEquals;

import java.util.Hashtable;
import java.util.Map.Entry;

import org.junit.Test;

import treeedit.RandomTreeGenerator;
import treeedit.Tree;

public class UtilsTest_RandomTree {
	String result = "fdacbe";

	@Test
	public void testGenerateTree() {
		Tree tree = RandomTreeGenerator.getFullRandomTree(4, 3, 3);
		System.out.println(tree.debugOutput());
		assertEquals("Result", 27, tree.getLeavesSize());
	}

	@Test
	public void testRandomizeTree() {
		Tree tree = RandomTreeGenerator.getFullRandomTree(3, 2, 2);
		// System.out.println(tree.debugOutput());
		Tree newTree = (Tree) tree.clone();
		RandomTreeGenerator.randomizeTree(newTree, 55);
		System.out.println(newTree.debugOutput());
		System.out.println(tree.debugOutput());
	}

	@Test
	public void testRandomizeSet() {
		// create random forest
		Hashtable<Integer, Tree> ht = new Hashtable<Integer, Tree>();
		for (int i = 0; i < 100; i++) {
			ht.put(i, RandomTreeGenerator.getFullRandomTree(3, 2, 2));
		}

		// create new forest based on the first one
		Hashtable<Integer, Tree> ht2 = new Hashtable<Integer, Tree>();
		for (Entry<Integer, Tree> entry : ht.entrySet()) {
			Tree newTree = (Tree) entry.getValue().clone();
			RandomTreeGenerator.randomizeTree(newTree, 10);
			ht2.put(entry.getKey(), newTree);
		}
	}
}
